package cn.edu.xmu.oomall.customer.controller;


import cn.edu.xmu.javaee.core.aop.Audit;
import cn.edu.xmu.javaee.core.aop.LoginUser;
import cn.edu.xmu.javaee.core.model.ReturnNo;
import cn.edu.xmu.javaee.core.model.ReturnObject;
import cn.edu.xmu.javaee.core.model.dto.UserDto;
import cn.edu.xmu.oomall.customer.service.CartsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController /*Restful的Controller对象*/
@RequestMapping(value = "/carts", produces = "application/json;charset=UTF-8")
@RequiredArgsConstructor
@Slf4j
public class CartsController {

    private final CartsService cartsService;

    /**
     * 买家删除购物商品
     * @param id
     * @param user
     * @return
     */
    @DeleteMapping({"/{id}"})
    @Audit(departName = "customer")
    public ReturnObject delCarts(@PathVariable Long id, @LoginUser UserDto user) {
        cartsService.delCarts(id, user);
        return new ReturnObject(ReturnNo.OK);
    }
}
